import { makeAutoObservable } from 'mobx'
import { getBarriers, getUserJobRel } from './api'
import { useLocation } from 'umi'
import { getData } from '@/servers/http'
import { api } from '@/servers/api'
import type { jobItem } from './interface'

class Store {
    barriersInfo: any = {}
    showFirst: boolean = false
    userInfo: any = {}
    jobList: jobItem[] = []
    loading: boolean = true

    constructor() {
        makeAutoObservable(this)
    }

    getBarriersInfo = (id: string) => {
        getBarriers(id).then(({ data }) => {
            this.barriersInfo = data
            document.title = data?.name || ''
            this.showFirst = data?.is_first_view === '1'
        })
    }

    resetBarriers = () => {
        this.barriersInfo = {}
    }

    handleClose = () => {
        this.showFirst = false
    }

    /** 获取用户信息 */
    getUserInfo = () => {
        return getData(api.usersLoginUserInfo).then((res: any) => {
            const { data, status } = res
            if (status !== 200) return
            this.userInfo = data
        })
    }

    /** 获取意向列表 */
    getUserJobRel = () => {
        return getUserJobRel().then((res: any) => {
            const { data, status } = res
            if (status !== 200) return
            this.jobList = data
            this.loading = false
        })
    }
}
export default Store
